/////////////////////////////////////////////////////page_rentalCarOrder////////////////////////
$(document).on("pageInit", "#page_rentalCarOrder", function(e, pageId, $page) {
    my.givetitle('租车订单');
      	    	   $('.infinite-scroll-preloader').show();
                   $('.infiniteOver').hide()
      	    	   key=my.get_key(my.getCookie('token'))
      	    	   var loading = false;
                   var RentalOrderType=1
                   var pageNow=1
                   var orderActiveList=my.getRentalCarOrderList(my.getCookie('id'),'','',key,1)
                    setTimeout(function(){
      	    	   if(orderActiveList!=''){
      	    	   	$('.order-list-rentalCar').empty()
      	    	    for(i=0;i<orderActiveList.order_list.length;i++){
      	    	   	  var list='<li id="'+orderActiveList.order_list[i].rental_orderid+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].rental_ordernum+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].brand_chinese_name+' '+orderActiveList.order_list[i].cars_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].order_startime+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].order_endtime+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.order_list[i].state_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'

           	           $('.order-list-rentalCar').append(list)
      	    	   }
      	    	    if(orderActiveList.order_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	   $('.order-list-rentalCar li').click(function(){
      	    	   	sessionStorage.orderid=$(this).attr('id')
      	    	   //	$.router.loadPage("rentalCarOrderDetails.html");
                       $.router.load(rentalCarOrderDetailsUrl,true);
      	    	   })
      	    	   }else{
      	    	   	    $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	   }
      	    	   },1000);

      	    	   //获取行程中订单开始
      	    	   $('.orderActive').click(function(){
      	    	   	RentalOrderType=1
      	    	   	pageNow=1
      	    	   	$(this).siblings('span').removeClass('active')
      	    	   	$(this).addClass('active')
      	    	   	$('.order-list-rentalCar').empty()
      	    	   	$('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	   	var orderActiveList=my.getRentalCarOrderList(my.getCookie('id'),'','',key,1)
      	    	   	setTimeout(function(){
      	    	   	if(orderActiveList!=''){
      	    	      for(i=0;i<orderActiveList.order_list.length;i++){
      	    	   	     var list='<li id="'+orderActiveList.order_list[i].rental_orderid+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].rental_ordernum+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].brand_chinese_name+' '+orderActiveList.order_list[i].cars_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].order_startime+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.order_list[i].order_endtime+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.order_list[i].state_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	    	            $('.order-list-rentalCar').append(list)
      	    	       }
      	    	      if(orderActiveList.order_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	       $('.order-list-rentalCar li').click(function(){
      	    	   	     sessionStorage.orderid=$(this).attr('id')
      	    	   	     //$.router.loadPage("rentalCarOrderDetails.html");
                           $.router.load(rentalCarOrderDetailsUrl,true);
      	    	       })
      	    	     }else{
      	    	   	    $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	   }
      	    	     },1000);

      	    	   })
      	    	   //获取行程中订单结束
      	    	    //获取已完成订单开始
      	    	   $('.orderOver').click(function(){
      	    	   	RentalOrderType=2
      	    	   	pageNow=1
      	    	   	$(this).siblings('span').removeClass('active')
      	    	   	$(this).addClass('active')
      	    	   	$('.order-list-rentalCar').empty()
      	    	   	$('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	   	var orderActiveList=my.getRentalCarOrderList(my.getCookie('id'),'','',key,2)
      	    	   	setTimeout(function(){
      	    	   	if(orderActiveList!=''){
      	    	      for(i=0;i<orderActiveList.order_list.length;i++){
      	    	   	     var list='<li id="'+orderActiveList.order_list[i].rental_orderid+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].rental_ordernum+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].brand_chinese_name+' '+orderActiveList.order_list[i].cars_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].order_startime+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.order_list[i].order_endtime+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.order_list[i].state_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	    	            $('.order-list-rentalCar').append(list)
      	    	       }
      	    	      if(orderActiveList.order_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	      $('.order-list-rentalCar li').click(function(){
      	    	   	     sessionStorage.orderid=$(this).attr('id')
      	    	   	     //$.router.loadPage("rentalCarOrderDetails.html");
                          $.router.load(rentalCarOrderDetailsUrl,true);
      	    	       })
      	    	     }else{

      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()


      	    	   }
      	    	     },1000)

      	    	   })
      	    	   //获取已完成订单结束
      	    	   //获取异常订单开始
      	    	   $('.orderAbnormal').click(function(){
      	    	   	RentalOrderType=3
      	    	   	pageNow=1
      	    	   	$(this).siblings('span').removeClass('active')
      	    	   	$(this).addClass('active')
      	    	   	$('.order-list-rentalCar').empty()
      	    	   	$('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	   	var orderActiveList=my.getRentalCarOrderList(my.getCookie('id'),'','',key,3)
      	    	   	setTimeout(function(){
      	    	   	if(orderActiveList!=''){
      	    	      for(i=0;i<orderActiveList.order_list.length;i++){
      	    	   	     var list='<li id="'+orderActiveList.order_list[i].rental_orderid+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].rental_ordernum+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].brand_chinese_name+' '+orderActiveList.order_list[i].cars_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].order_startime+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.order_list[i].order_endtime+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.order_list[i].state_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	    	            $('.order-list-rentalCar').append(list)
      	    	       }
      	    	      if(orderActiveList.order_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	      $('.order-list-rentalCar li').click(function(){
      	    	   	     sessionStorage.orderid=$(this).attr('id')
      	    	   	   //  $.router.loadPage("rentalCarOrderDetails.html");
                          $.router.load(rentalCarOrderDetailsUrl,true);
      	    	       })
      	    	     }else{
      	    	   	    $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	   }
      	    	     },1000);

      	    	   })
      	    	   //获取异常订单结束
      	    	   //无限加载
      	    	    $(document).off("infinite").on("infinite", ".page-current .infinite-scroll-rentalCarOrder", function() {
                    // 如果正在加载，则退出
                    if (loading) return;
                    pageNow=Math.ceil($('.page-current .order-list-rentalCar li').length/10+0.01)
                    console.log('pageNow:'+pageNow)
                    console.log('类型id:'+RentalOrderType)
                    loading = true;
                    setTimeout(function() {
                    loading = false;
                    var orderActiveList=my.getRentalCarOrderList(my.getCookie('id'),'10',pageNow,key,RentalOrderType)
      	    	   	if(orderActiveList!=''){
      	    	   		if(pageNow==1){
      	    	   		   $('.order-list-rentalCar').empty()
      	    	   		}
      	    	   		console.log('载入条数:'+orderActiveList.order_list.length)
      	    	        for(i=0;i<orderActiveList.order_list.length;i++){
      	    	   	            var list='<li id="'+orderActiveList.order_list[i].rental_orderid+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].rental_ordernum+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].brand_chinese_name+' '+orderActiveList.order_list[i].cars_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.order_list[i].order_startime+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.order_list[i].order_endtime+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.order_list[i].state_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	    	            $('.order-list-rentalCar').append(list)
      	    	       }
      	    	       if(orderActiveList.order_list.length<10){
      	    	           $.detachInfiniteScroll($('.infinite-scroll'));
                           $('.infinite-scroll-preloader').hide();
                           $('.infiniteOver').show()
      	    	       }
      	    	       $('.order-list-rentalCar li').click(function(){
      	    	      	  sessionStorage.orderid=$(this).attr('id')
      	    	     	//  $.router.loadPage("rentalCarOrderDetails.html");
                           $.router.load(rentalCarOrderDetailsUrl,true);
      	    	       })
      	    	     }else{
      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }
                   }, 2000);
               });
});